package com.health.viewscontrols.focusgroup;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import com.health.R;
import com.health.adapter.SearchDaAdapter;
import com.health.adapter.SearchDaAdapter2;
import com.health.model.JBBean;
import com.health.model.PeopleType;
import com.health.tools.SPUtil;
import com.health.viewscontrols.NovaActivity;
import com.health.viewscontrols.NovaApplication;

import java.util.ArrayList;
import java.util.List;

public class ScreenSearchActivity extends NovaActivity {

    private RadioButton rbMan;
    private RadioButton rbWoman;
    String sex = "";
    private String jbId = "";
    private RecyclerView rlJB;
    private ImageView iv_defman;
    private ImageView iv_defwoman;
    private ImageView iv_checkman;
    private ImageView iv_checkwoman;
    private Button bt_reset;
    private Button bt_confirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screensearch);
        rbMan = (RadioButton) findViewById(R.id.exam_mail);
        rbWoman = (RadioButton)findViewById(R.id.exam_famail);
        iv_defman = (ImageView)findViewById(R.id.iv_defman);
        iv_defwoman = (ImageView)findViewById(R.id.iv_defwoman);
        iv_checkman = (ImageView)findViewById(R.id.iv_checkman);
        iv_checkwoman = (ImageView)findViewById(R.id.iv_checkwoman);
        bt_confirm = (Button)findViewById(R.id.bt_confirm);
        bt_reset = (Button)findViewById(R.id.bt_reset);

        findViews();
        setListeners();
    }

    @Override
    public void findViews() {
        rlJB = (RecyclerView) findViewById(R.id.rl_jb);

        setAdapter();
    }

    private void setAdapter(){
        List<JBBean> jbData = new ArrayList<>();
        String str_jdrno = SPUtil.getStr_jdrno(ScreenSearchActivity.this);

        JBBean bean = new JBBean();
        bean.setJbName("一般人群");
        bean.setJbId("1");
        Log.e("TAG","一般人群数目："+NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.YBRQ));
        bean.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.YBRQ)+"");
        jbData.add(bean);
        JBBean bean2 = new JBBean();
        bean2.setJbName("儿童");
        bean2.setJbId("2");
        bean2.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.CHILD)+"");
        jbData.add(bean2);
        JBBean bean3 = new JBBean();
        bean3.setJbName("高血压");
        bean3.setJbId("6");
        bean3.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.GXY)+"");
        jbData.add(bean3);
        JBBean bean4 = new JBBean();
        bean4.setJbName("糖尿病");
        bean4.setJbId("7");
        bean4.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.TNB)+"");
        jbData.add(bean4);
        JBBean bean5 = new JBBean();
        bean5.setJbName("精神病");
        bean5.setJbId("5");
        bean5.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.JSB)+"");
        jbData.add(bean5);
        JBBean bean6 = new JBBean();
        bean6.setJbName("脑卒中");
        bean6.setJbId("9");
        bean6.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.NCZ)+"");
        jbData.add(bean6);
        JBBean bean7 = new JBBean();
        bean7.setJbName("冠心病");
        bean7.setJbId("8");
        bean7.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.GXB)+"");
        jbData.add(bean7);
        JBBean bean8 = new JBBean();
        bean8.setJbName("残疾人");
        bean8.setJbId("10");
        bean8.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.CJR)+"");
        jbData.add(bean8);
        JBBean bean9 = new JBBean();
        bean9.setJbName("孕产妇");
        bean9.setJbId("3");
        bean9.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.WOMAN)+"");
        jbData.add(bean9);
        JBBean bean10 = new JBBean();
        bean10.setJbName("老年人");
        bean10.setJbId("4");
        bean10.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.OLD)+"");
        jbData.add(bean10);
        JBBean bean11 = new JBBean();
        bean11.setJbName("肺结核");
        bean11.setJbId("11");
        bean11.setJbNum(NovaApplication.dbManger.getCountByJDRType(str_jdrno, PeopleType.FJH)+"");
        jbData.add(bean11);

        SearchDaAdapter2 adapter = new SearchDaAdapter2(ScreenSearchActivity.this, jbData, jbData.size(), new SearchDaAdapter2.OnClickListener() {

            @Override
            public void setOnClickItemListener(View view, int position, String name, String id) {
                Log.e("TAG","点击疾病："+name+"--"+id);
                jbId = id;
            }
        });
        rlJB.setAdapter(adapter);
        GridLayoutManager manager = new GridLayoutManager(ScreenSearchActivity.this, 6);

        //设置布局管理者
        rlJB.setLayoutManager(manager);
    }

    @Override
    public void setListeners() {
        iv_defman.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iv_defman.setVisibility(View.GONE);
                iv_checkman.setVisibility(View.VISIBLE);
                iv_defwoman.setVisibility(View.VISIBLE);
                iv_checkwoman.setVisibility(View.GONE);
                sex = "DM01-08_1";
            }
        });

        iv_defwoman.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iv_defwoman.setVisibility(View.GONE);
                iv_checkwoman.setVisibility(View.VISIBLE);
                iv_defman.setVisibility(View.VISIBLE);
                iv_checkman.setVisibility(View.GONE);
                sex = "DM01-08_2";
            }
        });

        bt_reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sex = "";
                jbId = "";
                iv_checkwoman.setVisibility(View.GONE);
                iv_checkman.setVisibility(View.GONE);
                iv_defwoman.setVisibility(View.VISIBLE);
                iv_defman.setVisibility(View.VISIBLE);
                setAdapter();
            }
        });

        bt_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent inte = new Intent();
                inte.putExtra("sex",sex);//这里是键值对，“data”是键
                inte.putExtra("jb",jbId);//这里是键值对，“data”是键
                setResult(600,inte);//返回值，2 是改返回的标志，也会返回
                finish();
            }
        });
    }
}
